<?php
/*
通用分类
*/

define('Acache_no','1');
class Con_anav extends Acan{
	public $defaultAct='index';
	public $Conread = '导航管理';
	public $Actread = array('index'=>'列表','save'=>'保存','add'=>'添加','del'=>'删除','delall'=>'删除所有');
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		if(empty($this->id) || $this->id == '*'){$this->id = '0';}
		$this->model = Afun_db()->model(Acan_table_navs);
		if($_POST){Afun_cache_rm('Anav');}//有数据库操作删除导航缓存
		$this->atitle = $this->Actread[$this->Aact];
	}
	function Act_anmp(){
			if($this->id=='up'){
				$anav_data = Afunc_nav()->anav_data('anmp');//获取菜单
				Afun_filecache_set('Anav-anmp'.$this->Amode,$anav_data,0,'./adata/navs/');
				Afun_refresh('更新成功','referrer');
			}
			echo '<a href="'.$this->Aactr.'-up">更新</a>';
	}
	function Act_index(){
		$form_val_is_target = array('1'=>'是','0'=>'否');
		$form_val_is_show = array('1'=>'是','2'=>'否');
		$form_val_if_url = array('1'=>'是','0'=>'否');
		$obj = Afun_acan_new('list');
		$key_name = $this->model->key_name;
		$columnrr = $this->model->comment;//初始栏目
		$column = $obj->column($this->model,$columnrr,$_POST['acolumn']);
		$column_html = $obj->column_html($this->model,$column,'Aform');
		$column_json = $obj->form_json($this->model);
		//分页函数
		$con->where = "`pid`='$this->id'";
		$page->theurl = $this->Aactr.'-'.$this->id;
		$page->by = $this->model->key_name;
		$page->page = '20';
		$page->counts = $this->model->count($con);	//统计总数目
		$pages = Afun_apage($page);
		$con->order = "a.if_show asc,a.look asc,a.$pages->orderby";
		$con->limit = $pages->limit;
		//分页结束
		$result = $this->model->findAll($con);
		foreach ($result as $key => $val) {
			if($_GET['search']){
				$val['name']=preg_replace("/($key)/i","<font color=red><b>\\1</b></font>",$val['name']);
			}
			$list[] = $val;
		}
		//获取父菜单信息
		$listp= $this->model->ofindPk($this->id);
		include $this->Atpl();
	}
	//保存
	function Act_save(){
		Afun_post_auth();
		$savedata = $_POST['save'];
		if($this->id == 'one'){
			$key = $savedata[$this->model->key_name];
			unset($savedata[$this->model->key_name]);
			if(!empty($key)){
				$msg = $this->model->updatePk($savedata,$key);
			}else{
				$msg = $this->model->save($savedata);
			}
		}elseif(is_array($savedata)){
			foreach($savedata as $i=>$vals){
				$this->model->updatePk($vals,$vals['key']);
			}
		}
		Afun_cache_rm('Anav');
		Afun_json($msg);
	}
	//添加
	function Act_add(){
		Afun_post_auth();
		if(empty($_POST['add']['pid']))
			$_POST['add']['pid'] = $this->id;
		if($this->model->save($_POST['add'])){
			Afun_cache_rm('Anav');
			Afun_refresh('添加成功','referrer');
		}else{Afun_refresh('添加失败','referrer');}
	}
	//删除
	function Act_del(){
		Afun_post_auth();
		if($this->model->deletePk($this->id)){
			Afun_cache_rm('Anav');
			Afun_refresh('删除成功','referrer');
		}
	}
	//删除所选
	function Act_delall(){
		Afun_post_auth();
		foreach($_POST['chk'] as $key=>$val){
			if(empty($vala))
				$vala = "'$val'";
			else
				$vala .=",'$val'";
		}
		$this->model->delete($this->model->key_name." IN ($vala)");
		Afun_cache_rm('Anav');
		Afun_refresh("删除成功",'referrer');
	}
	
}

?>